<?php


/** @see Zend_Controller_Action */
require_once 'Zend/Controller/Action.php';

/**
 * Controleur d'action principal
 */
class DatasourceController extends Zend_Controller_Action
{

    /**
     * Simple use of datagrid
     */
    public function indexAction()
    {
        $this->bAction();
    }

    public function aAction()
    {
        //set the name of datagrid when creating the grid object
        // the name for each datagrid is oblige
        $grid = new Zend_DataGrid('gridName');

        $datasource = $this->getDatasource();

        $grid->setDatasource($datasource);
        //or $grid->dataBind($datasource);

        //$grid->setRendererOption('showHeader', true);
        //$grid->setRendererOption('showFooter', true);
        $grid->setShowFooter(true);

        //assign to the view
        $this->view->grid = $grid;
    }

    public function bAction()
    {
        set_include_path(
            APP_BASE_PATH . '/application/models'
            . PATH_SEPARATOR
            . get_include_path()
        );

        require_once 'Model_ExampleGrid.php';

        $datasource = $this->getDatasource();

        //creating the datagrid object
        $grid = new Model_ExampleGrid();

        $grid->dataBind($datasource);

        //assign to the view
        $this->view->grid = $grid;
    }

    public function cAction()
    {
        //or use the option array
        $otherOpions = array('' => '');

        //creating the datagrid object
        $grid = new Zend_DataGrid('gridName', $otherOpions);

        $this->view->grid = $grid;
    }

    public function dAction()
    {
        $options = array('name' => 'gridName');

        //or use Zend_Config object
        $config = new Zend_Config($options);

        //creating the datagrid object
        $grid = new Zend_DataGrid($config);

        $this->view->grid = $grid;
    }

    public function eAction()
    {
        $options = array('name' => 'gridName');

        //or use Zend_Config object
        $config = new Zend_Config($options);

        //creating the datagrid object
        $grid = new Zend_DataGrid('gridName', $config);

        $this->view->grid = $grid;
    }

    private function getDatasource()
    {
        return $datasource = array(
            array('colName' => 'Test 24', 'col1' => 'valcol11', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Folie Foli', 'col1' => 'tetet', 	'col2' => 'ploio', 	 'col3' => 'volieze'),
            array('colName' => 'Best grid', 'col1' => 'valcol21', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Last Value', 'col1' => 'valcol31', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Do them', 'col1' => 'valcol41', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'All people', 'col1' => 'valcol51', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Right', 'col1' => 'valcol61', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Oha', 'col1' => 'valcol71', 'col2' => 'valcol1', 'col3' => 'valcol1'),
            array('colName' => 'Hi', 'col1' => 'valcol81', 'col2' => 'valcol1', 'col3' => 'valcol1'),
        );
    }

}
